package ioc

import (
	"github.com/spf13/viper"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	followv1 "jk-time/webook/api/proto/gen/follow/v1"
)

func InitFollowClient() followv1.FollowServiceClient {
	type Config struct {
		Addr   string `yaml:"addr"`
		Secure bool   `yaml:"secure"`
	}
	var config Config
	err := viper.UnmarshalKey("grpc.client.follow", &config)
	if err != nil {
		panic(err)
	}

	var opts []grpc.DialOption
	if !config.Secure {
		opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
	}
	cc, err := grpc.Dial(config.Addr, opts...)
	if err != nil {
		panic(err)
	}

	return followv1.NewFollowServiceClient(cc)
}
